package com.itqf.service.impl;

import com.itqf.mapper.RoleMapper;
import com.itqf.pojo.Role;
import com.itqf.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * projectName: rbacgp8
 *
 * @author: 赵伟风
 * time: 2021/8/12 17:26
 * description:
 */
@Service
public class RoleServiceImpl  implements RoleService {

    @Autowired
    private RoleMapper roleMapper;

    /**
     * 查询所有角色
     *
     * @return
     */
    @Override
    public List<Role> findAll() {
        return roleMapper.queryAll();
    }

    /**
     * 用户id查询已经存在的角色
     *
     * @param uid
     * @return
     */
    @Override
    public List<Role> findHasAll(int uid) {
        return roleMapper.queryHasAll(uid);
    }

    @Override
    public List<String> findHasAllStr(int uid) {
        List<Role> roles = roleMapper.queryHasAll(uid);

        List<String> roleNames = new ArrayList<>();
        for (Role role : roles) {
            roleNames.add(role.getrName());
        }

        return roleNames;
    }
}
